package com.wan37.logic.listener.handler;

import com.wan37.logic.domain.vo.BackpackVO;
import com.wan37.logic.domain.vo.MessageVO;
import com.wan37.logic.email.EmailManager;
import com.wan37.logic.email.handler.CGameWorldPlayerEmailHandler;
import com.wan37.logic.global.reference.SpringContextHolder;
import com.wan37.logic.listener.annotation.EventHandler;
import com.wan37.logic.listener.annotation.Listener;
import com.wan37.logic.listener.event.EventType;
import com.wan37.logic.listener.event.user.UserLoginEvent;
import com.wan37.logic.service.cache.WeaponryServiceCache;
import org.springframework.context.event.EventListener;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : luoyong
 * @date : 2020-07-29 10:38
 **/
@Listener
public class EmailListenerHandler {
    private EmailManager emailManager;
    private WeaponryServiceCache weaponryServiceCache;
    /**
     * 用户登入将用户的历史邮件推给用户
     */
    @EventHandler(EventType.LOGIN)
    public void login(UserLoginEvent userLoginEvent){
        //简单测试发送邮件功能
//        test();
        CGameWorldPlayerEmailHandler cGameWorldPlayerEmailHandler = new CGameWorldPlayerEmailHandler(new MessageVO());
        cGameWorldPlayerEmailHandler.getAllEmail(userLoginEvent.getUserId());
    }

    public void test(){
        this.emailManager = SpringContextHolder.getBean("emailManager");
        this.weaponryServiceCache = SpringContextHolder.getBean("weaponryServiceCache");
        List<String> userIdList = new ArrayList<>();
        userIdList.add("3");
        userIdList.add("2");
        List<BackpackVO> backpackVOList = new ArrayList<>();
        backpackVOList.add(weaponryServiceCache.getWeaponryServiceMap().get("100001").getWeaponryVO());
        emailManager.sendEmail("你有一份外卖订单需要确定哦。", "admin", userIdList, backpackVOList);
    }
}
